home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Especial Multimedia
/
Especial Multimedia.iso
/
Multimed
/
Prg
/
WAVSHOW.ZIP
/
READ.ME
< prev
next >
Wrap
Text File
|
1997-09-14
|
4KB
|
97 lines
WavShow - A Simple 8-bit .WAV file displayer in Borland's Delphi.
Written by Pete Cervasio on April 8, 1995.
Released to the public domain.
Okay, here's a simple 8-bit .WAV file displayer. It's not much, and it
could use some more work, but it shows how to do it. I haven't bothered to
read the wave file to make sure it's 8-bit, mono. I'm also making the
assumption that the wave header is 44 bytes long, even though some programs
(like GoldWave) put extra info in there.
This software is hereby placed into the public domain. I sure don't want
it. <grin> If you really feel that you need to give someone money for it,
then send it to a charity that helps needy children. On second thought, do
that even if you don't. There are no warranties that this will do anything
but take up room on your disk drive. If it fails to do that, you need to
download another copy.
One part of the code that I like is in the Open button OnClick method:
WaveBytes := FileSize (WaveFile) - WaveHdrSize;
BytesPerSBPosition := 1;
First, we find out how large the data portion of the file is, and set the
default value of how many bytes to move in the file for a change of 1 in the
scrollbar.
while (WaveBytes div BytesPerSBPosition) > 32767 do
inc(BytesPerSBPosition);
Here, we want to make sure that we will be able to use the scrollbar to
reach the far end of the file. Since the maximum we can use is $FFFF, we
keep dividing the file size by increasingly larger numbers until it gets
down to something we can use.
if WaveBytes div BytesPerSBPosition > PaintBox1.Width then
begin
ScrollBar1.Visible := True;
ScrollBar1.Max := WaveBytes div BytesPerSBPosition
- PaintBox1.Width;
end
else
ScrollBar1.Visible := False;
Now we are doing some fudging. If the size of the file is less than the
width of the paintbox, we don't need to see the scrollbar. If it is larger,
then we show the scrollbar and set the max. We're subtracting the width of
the paintbox to keep the last byte of the file on the right hand side of the
paintbox when the scrollbar is at max. Comment out the subtraction and
you'll see what I mean. Finally:
if ScrollBar1.Position <> 0 then
ScrollBar1.Position := 0
else
PaintBox1.Refresh;
If we're opening a second file, we may have a scrollbar that is scrolled off
the 0 mark. Setting it to 0 forces a refresh of the paintbox (it's magic!).
Otherwise, we just refresh it manually.
Over in the OnPaint method for the paintbox component, we're doing this:
CurrPos := (ScrollBar1.Position * BytesPerSBPosition) + WaveHdrSize;
Seek (WaveFile, CurrPos);
First, we figure out where in the file we should be. This is why we needed
to calculate the BytesPerSBPosition thingie.
with PaintBox1.Canvas do
begin
FillChar (ReadBuffer, SizeOf(ReadBuffer), $80);
BlockRead (WaveFile, ReadBuffer, ClipRect.Right, NumRead);
Pen.Color := clLime;
MoveTo (0, ReadBuffer[0] shr 1); { 128 bit high picture }
for X := 1 to NumRead - 1 do
LineTo (X, ReadBuffer[X] shr 1);
end;
This part fills the buffer with $80, which is what 8-bit .wav files use for
no audio. Then we read in as many bytes as the canvas is wide. I use
clLime for the pen, since it shows up nice on black. Finally, we move to
the first position, and draw lines to the rest. The code above is based on
the picture box being just about 128 pixels high, hence the division of the
values read from the .wav file by 2.
The rest is all easier than this was. Have fun and enjoy!
Oh, I guess I ought to include the standard email junk:
73443,1426 on Compuserve (73443.1426@compuserve.com)
1:130/209.0 on Fidonet (pete.cervasio@p0.f209.n130.z1.fidonet.org)
or something like that...